package com.ymttest.business.service.shenqi;

import java.util.Arrays;

import com.shop2cn.iapi.activity.parameter.GetActivityListReq;
import com.shop2cn.iapi.activity.service.GetActivityListCall;
import com.shop2cn.iapi.activitymgt.parameter.ActivityProductListReq;
import com.shop2cn.iapi.activitymgt.parameter.response.ActivityProductListResp;
import com.shop2cn.iapi.activitymgt.service.ActivityProductListCall;

public class SqActivityService {

	public static int getActivityList(long merchantId, int activityId)
			throws Exception {

		GetActivityListReq getActivityListReq = new GetActivityListReq();
		GetActivityListCall getActivityListCall = new GetActivityListCall();

		getActivityListReq.setMerchantId(merchantId);
		getActivityListReq.setActivityIdList(Arrays.asList(activityId));

		getActivityListCall.setData(getActivityListReq);
		getActivityListCall.callService();

		if (null == getActivityListCall.getData())
			return 0;

		return getActivityListCall.getData().getJSONArray("activityList")
				.getJSONObject(0).getInt("activityType");
	}

	public static ActivityProductListResp getActivityProductList(Long activityId, Long sellerId) {

		ActivityProductListReq activityProductListReq = new ActivityProductListReq();
		ActivityProductListCall activityProductListCall = new ActivityProductListCall();

		activityProductListReq.setActivityid(activityId.intValue());
		activityProductListReq.setPageIndex(1);
		activityProductListReq.setPageSize(10);
		activityProductListReq.setSellerId(sellerId);

		try {

			activityProductListCall.setData(activityProductListReq);
			activityProductListCall.callService();

			return activityProductListCall.getActivityProductListResp();
		} catch(Exception e) {

			e.printStackTrace();

			return null;
		}
	}
	
	public static void main(String[] args) throws Exception {

		System.out.print(SqActivityService.getActivityProductList(500018674L,
				502381949L));
	}
}
